/*     */ package com.gillion.grule.client.validator;
/*     */ 
/*     */ import com.google.common.collect.Maps;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.apache.commons.lang3.Validate;
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Validator
/*     */ {
/*  13 */   private static Map<String, String> validatorMap = Maps.newConcurrentMap();
/*     */   static {
/*  15 */     validatorMap.put("range", "com.gillion.grule.client.validator.RangeValidatorServiceImpl");
/*  16 */     validatorMap.put("pattern", "com.gillion.grule.client.validator.PatternValidatorServiceImpl");
/*  17 */     validatorMap.put("length", "com.gillion.grule.client.validator.LengthValidatorServiceImpl");
/*  18 */     validatorMap.put("require", "com.gillion.grule.client.validator.RequireValidatorServiceImpl");
/*  19 */     validatorMap.put("notEmpty", "com.gillion.grule.client.validator.NotEmptyValidatorServiceImpl");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean validate(List<Object> content, Map<String, Object> settings) {
/*  30 */     boolean flag = true;
/*  31 */     Validate.notNull(settings, "settings不能为空！", new Object[0]);
/*  32 */     if (content != null) {
/*  33 */       flag = doValidator(content, settings);
/*     */     }
/*     */     
/*  36 */     return flag;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean validate(Object object, Map<String, Object> settings) {
/*  46 */     Validate.notNull(settings, "settings不能为空！", new Object[0]);
/*  47 */     if (object instanceof List) {
/*  48 */       return validate((List<Object>)object, settings);
/*     */     }
/*  50 */     Map<String, Object> context = (Map<String, Object>)object;
/*  51 */     return validate(context, settings);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   private boolean doValidator(List<Object> content, Map<String, Object> settings) {
/*  57 */     boolean flag = true;
/*  58 */     for (Object element : content) {
/*  59 */       if (element instanceof Map) {
/*  60 */         flag = validate(element, settings);
/*  61 */         if (!flag) {
/*     */           break;
/*     */         }
/*     */       } 
/*     */     } 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/*  70 */     return flag;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean validate(Map<String, Object> content, Map<String, Object> settings) {
/*  81 */     boolean flag = true;
/*  82 */     Validate.notNull(settings, "settings不能为空！", new Object[0]);
/*     */     
/*  84 */     Set<String> keys = settings.keySet();
/*  85 */     for (String key : keys) {
/*  86 */       Object value = null;
/*  87 */       if (content != null) {
/*  88 */         value = content.get(key);
/*     */       }
/*     */       
/*  91 */       Map<String, Object> validatorSettings = (Map<String, Object>)settings.get(key);
/*  92 */       Set<String> validatorKeys = validatorSettings.keySet();
/*  93 */       for (String validatorKey : validatorKeys) {
/*  94 */         flag = doValidator(key, value, validatorSettings, validatorKey);
/*  95 */         if (!flag) {
/*     */           break;
/*     */         }
/*     */       } 
/*     */     } 
/* 100 */     return flag;
/*     */   }
/*     */   
/*     */   private boolean doValidator(String key, Object value, Map<String, Object> validatorSettings, String validatorKey) {
/* 104 */     ValidatorService validatorService = null;
/*     */     
/*     */     try {
/* 107 */       validatorService = (ValidatorService)Class.forName(validatorMap.get(validatorKey)).newInstance();
/* 108 */     } catch (InstantiationException e) {
/* 109 */       e.printStackTrace();
/* 110 */       throw new RuntimeException("无法找到名称为：" + validatorKey + "的校验器");
/* 111 */     } catch (IllegalAccessException e) {
/* 112 */       e.printStackTrace();
/* 113 */       throw new RuntimeException("无法找到名称为：" + validatorKey + "的校验器");
/* 114 */     } catch (ClassNotFoundException e) {
/* 115 */       throw new RuntimeException("无法找到名称为：" + validatorKey + "的校验器");
/*     */     } 
/* 117 */     Map<String, Object> validatorSetting = (Map<String, Object>)validatorSettings.get(validatorKey);
/* 118 */     boolean flag = validatorService.validate(key, value, validatorSetting);
/* 119 */     return flag;
/*     */   }
/*     */ }


/* Location:              D:\apache-tomcat-9.0.76\webapps\grule-manager\WEB-INF\lib\grule-client-2.0.2.RELEASE.jar!\com\gillion\grule\client\validator\Validator.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */